import { BaseContext, UUID, IContext } from '../../../src';
import { SelectItem } from 'primeng/primeng';

export abstract class IdentityContext extends BaseContext {
    identity: string = UUID.next().substring(0, 4);
    fromComponent: string = '';
    fromApplication: string = '';
}

export class HelloworldContext extends IdentityContext {
    hello: string;
}

export class SubContextTypeChanged extends IdentityContext {
    preContextType: string;
    curContextType: string;
}

export class SendContextContent extends IdentityContext {
    sendContextType: string;
    sendContextContent: string;
}


export const getAllContextTypes = function (): SelectItem[] {
    let contextTypes: SelectItem[] = [];

    let defaultHello = new HelloworldContext();
    defaultHello.hello = 'hello';
    contextTypes.push({ label: defaultHello.contextClass, value: { type: defaultHello.contextClass, default: defaultHello } });

    let defaultSub = new SubContextTypeChanged();
    defaultSub.preContextType = 'empty';
    defaultSub.curContextType = 'empty';
    contextTypes.push({ label: defaultSub.contextClass, value: { type:  defaultSub.contextClass, default: defaultSub } });

    let defaultSend = new SendContextContent();
    defaultSend.sendContextType = 'empty';
    defaultSend.sendContextContent = 'empty';
    contextTypes.push({ label:  defaultSend.contextClass, value: { type:  defaultSend.contextClass, default: defaultSend } });

    return contextTypes;
}

export const getContextDesc = function (context: IdentityContext): string {
    let desc =
        `app  : ${context.fromApplication}
         comp : ${context.fromComponent}
         cId  : ${context.identity}
         cType: ${context.contextClass}`;

    return desc;
}

export const getContextDetail = function (context: IContext): string {
    return JSON.stringify(context, null, 2);
}

export function getUUID(length: number = 4) {
    return UUID.next().substring(0, length);
}